package cn.ejiajunxy.manager.provider;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.leo.baseui.mutiType.base.ItemViewProvider;

import cn.ejiajunxy.manager.R;
import cn.ejiajunxy.manager.fragment.PriceDialog;
import cn.ejiajunxy.manager.model.MoneyModel;


/**
 * Created by zhangguobao on 2018/3/17.
 */
public class MoneyProvider
        extends ItemViewProvider<MoneyModel, MoneyProvider.ViewHolder> {
    PriceDialog mPriceDialog;

    public MoneyProvider(Context context) {
        mPriceDialog = new PriceDialog(context);
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.row_money, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final MoneyModel money) {
        holder.tvNo.setText("¥" + money.finance.activeAmount);
        holder.tvGet.setText("¥" + (money.finance.haveAmount - money.finance.useAmount - money.finance.activeAmount));
        holder.tvEarn.setText("¥" + money.finance.haveAmount);
        holder.rlGet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPriceDialog.maxPrice = (float) (money.finance.haveAmount - money.finance.useAmount - money.finance.activeAmount);
                mPriceDialog.show();
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvEarn;
        TextView tvGet;
        TextView tvNo;
        RelativeLayout rlGet;

        ViewHolder(View itemView) {
            super(itemView);
            tvEarn = itemView.findViewById(R.id.tvEarn);
            tvGet = itemView.findViewById(R.id.tvGetMoney);
            tvNo = itemView.findViewById(R.id.tvNotMoney);
            rlGet = itemView.findViewById(R.id.rlGet);
        }
    }
}